# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Contributor: Valery Kartel <valery.kartel@gmail.com>
# Maintainer: Natanael Copa <ncopa@alpinelinux.org>
pkgname=p7zip
pkgver=16.02
pkgrel=3
pkgdesc="A command-line port of the 7zip compression utility"
url="http://p7zip.sourceforge.net"
arch="all"
license="LGPL-2.0-or-later"
subpackages="$pkgname-doc"
makedepends="bash yasm nasm"
source="https://downloads.sourceforge.net/sourceforge/p7zip/p7zip_${pkgver}_src_all.tar.bz2
	CVE-2016-9296.patch
	CVE-2017-17969.patch
	CVE-2018-5996.patch
	CVE-2018-10115.patch
	"
builddir="$srcdir/p7zip_$pkgver"

# secfixes:
#   16.02-r3:
#     - CVE-2018-5996
#     - CVE-2018-10115
#   16.02-r2:
#     - CVE-2017-17969
#   16.02-r1:
#     - CVE-2016-9296

prepare() {
	default_prepare

	local makefile="makefile.linux_any_cpu_gcc_4.X"
	case "$CARCH" in
		x86)    makefile="makefile.linux_x86_asm_gcc_4.X" ;;
		x86_64) makefile="makefile.linux_amd64_asm" ;;
	esac

	ln -sf $makefile makefile.machine

	sed -e "s,g++,${CXX:-g++}," -i makefile.machine
	sed -e "s,gcc,${CC:-gcc}," -i makefile.machine
}

check() {
	make test
}

build() {
	make all3 OPTFLAGS="$CXXFLAGS"
}

package() {
	make install DEST_DIR="$pkgdir" DEST_HOME="/usr" \
		DEST_MAN="/usr/share/man" \
		DEST_SHARE_DOC="/usr/share/doc/$pkgname"

	install -Dm755 contrib/gzip-like_CLI_wrapper_for_7z/$pkgname \
		"$pkgdir"/usr/bin/$pkgname
	install -Dm644 contrib/gzip-like_CLI_wrapper_for_7z/man1/$pkgname.1 \
		"$pkgdir"/usr/share/man/man1/$pkgname.1
}

sha512sums="d2c4d53817f96bb4c7683f42045198d4cd509cfc9c3e2cb85c8d9dc4ab6dfa7496449edeac4e300ecf986a9cbbc90bd8f8feef8156895d94617c04e507add55f  p7zip_16.02_src_all.tar.bz2
7a7fddf4122c3f5d4632640149a94c285a18515f38510388709c2fb9ecd450f9f34ae2e5fe4926c1c68507567b0affa2c8e9194c732673171dd5ee625192b194  CVE-2016-9296.patch
22b6437770f2fb70675ed6971239ec3d40d5b9c7e1c5aa28c670d082bd2e7d861863f2f00feacec759eab216081dc49544b980b2ebe9fe40c7d0d1ca1dfc3069  CVE-2017-17969.patch
7962a03430b94aec7c93d6dabee340f4f5915d728ba4df0dcaae483ab9c29115818e5e944572a3fd910addad8799c6a1e3911f6a0a02b661f804eea11c3a0f40  CVE-2018-5996.patch
757d0f50ccce2a21dce81f165a9f408a71ea53c226ef29b4d3843f30b2fc518d06cd784e2de644904813cd16a87f24387c5cc35c2499b1df9d86377057be032a  CVE-2018-10115.patch"
